﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using BCDto.Sim.CompanyBusinessType;
using BCService.Sim.Company.CompanyBusinessType;
using BCService.Utils;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace BCTMSRESTful.Controllers.Management.Organization.CompanyBusinessType
{
    /// <summary>
    /// 公司业务类型
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class CompanyBusinessTypeController : ManagementBaseController
    {
        private readonly ICompanyBusinessTypeService companyBusinessTypeService;

        public CompanyBusinessTypeController(ICompanyBusinessTypeService companyBusinessTypeService)
        {
            this.companyBusinessTypeService = companyBusinessTypeService;
        }

        #region 添加公司业务类型
        /// <summary>
        ///  添加公司业务类型
        /// </summary>
        /// <param name="requestDto">公司业务类型信息</param>
        /// <response code="201">添加公司业务类型成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加公司业务类型")]
        [ProducesResponseType(typeof(CompanyBusinessTypeDto), 201)]
        public IActionResult Post(
            [FromBody]CompanyBusinessTypeRequestDto requestDto)
        {
            var result = this.companyBusinessTypeService.Add(requestDto);
            return this.Created(string.Format("api/v1/sim/CompanyBusinessType/{0}", result.CompanyBusinessTypeId), result);
        }
        #endregion

        #region 修改公司业务类型
        /// <summary>
        ///  修改公司业务类型
        /// </summary>
        /// <param name="companyBusinessTypeId">公司业务类型Id</param>
        /// <param name="requestDto">公司业务类型信息</param>
        /// <response code="200">修改公司业务类型成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{company_business_type_id}")]
        [Log("修改公司业务类型")]
        [ProducesResponseType(typeof(CompanyBusinessTypeDto), 200)]
        public IActionResult Put([FromRoute(Name = "company_business_type_id")]int companyBusinessTypeId, [FromBody]CompanyBusinessTypeRequestDto requestDto)
        {
            CompanyBusinessTypePutDto putDto = requestDto.As<CompanyBusinessTypePutDto>();
            putDto.CompanyBusinessTypeId = companyBusinessTypeId;
            return this.Ok(this.companyBusinessTypeService.Update(putDto));
        }
        #endregion

        #region 删除公司业务类型
        /// <summary>
        ///  删除公司业务类型
        /// </summary>
        /// <param name="companyBusinessTypeId">公司业务类型Id</param>
        /// <response code="204">删除公司业务类型成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{company_business_type_id}")]
        [Log("删除公司业务类型")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "company_business_type_id")]int companyBusinessTypeId)
        {
            this.companyBusinessTypeService.Delete(companyBusinessTypeId);
            return this.NoContent();
        }
        #endregion

        #region 获取公司业务类型
        /// <summary>
        ///  获取公司业务类型
        /// </summary>
        /// <param name="companyBusinessTypeId">公司业务类型Id</param>
        /// <response code="200">获取公司业务类型</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{company_business_type_id}")]
        [ProducesResponseType(typeof(CompanyBusinessTypeDto), 200)]
        public IActionResult Get([FromRoute(Name = "company_business_type_id")]int companyBusinessTypeId)
        {
            return this.Ok(this.companyBusinessTypeService.GetEntity(companyBusinessTypeId));
        }
        #endregion

        #region 获取公司业务类型列表
        /// <summary>
        ///  获取公司业务类型列表
        /// </summary>
        /// <response code="200">获取公司业务类型列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(CompanyBusinessTypeDto), 200)]
        public IActionResult Get()
        {
            return this.Ok(this.companyBusinessTypeService.GetList());
        }
        #endregion

        #region 获取公司业务类型（分页）
        /// <summary>
        ///  获取公司业务类型（分页）
        /// </summary>
        /// <param name="companyBusinessTypeName">公司业务类型名称</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取公司业务类型（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<CompanyBusinessTypeDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "company_business_type_name")]string companyBusinessTypeName,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10)
        {
            return this.Ok(this.companyBusinessTypeService.Query(companyBusinessTypeName, start, end, index, size));
        }
        #endregion

    }
}
